var restify = require('restify');
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('database/rwdata.sq3');

function firstgraph(req, res, next) {
    db.serialize(function() {
        var sql = "select timestamp date, time close from ORATMS where statistic='DB time'";

        // Print the records as JSON
        db.all(sql, function(err, rows) {
            res.send(JSON.stringify(rows));
        });
    });
}

var server = restify.createServer();

server.get('/firstgraph/', firstgraph);

server.get(/\/html\/?.*/, restify.serveStatic({
    directory: './public'
}));

server.listen(8081, function() {
    console.log('%s listening at %s', server.name, server.url);
});
